package com.blb.friendsO.utils;

import javax.servlet.ServletContext;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//图标工具类
public class IconUtil {

    //加载图标
    public static List<String> loadIcon(ServletContext servletContext) throws IOException {
        ArrayList<String> list = new ArrayList<>();
//        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("/static/iconfont/iconfont.css");
        InputStream in = servletContext.getResourceAsStream("/static/iconfont/iconfont.css");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        IOUtils.readWrite(in,os);
        String body = os.toString();

        Pattern pattern = Pattern.compile(".icon-[\\w-]+");
        Matcher matcher = pattern.matcher(body);
        while (matcher.find()){
            String str = matcher.group().replace(".", "");
            list.add(str);
        }
        return list;
    }


}
